import { createRouter,createWebHashHistory } from "vue-router";
import { isLogined } from "../utils/tools";


const router = createRouter({
  history: createWebHashHistory(),
  routes: [
  {
    path:'/',
    name:"Home",
    component:()=>import('../views/Home.vue'),
  },
  {
    path:'/search',
    name:"Search",
    component:()=>import('../views/Search.vue'),
    meta:{
      hideNav:true,  //底部导航是否隐藏
    }
  },
  {
    path:'/detail',
    name:"Detail",
    component:()=>import('../views/Detail.vue'),
    meta:{
      hideNav:true,  //底部导航是否隐藏
    }
  },
  {
    path:'/Order',
    name:"Order",
    component:()=>import('../views/Order.vue'),
    meta:{
      hideNav:true,  //底部导航是否隐藏
    }
  },
  {
    path:'/login',
    name:"Login",
    component:()=>import('../views/Login.vue'),
    meta:{
      hideNav:true,  //底部导航是否隐藏
    }
  },
  {
    path:'/collection',
    name:"Collection",
    component:()=>import('../views/Collection.vue'),
    meta:{
      needLogin:true,// 需要登录
    }
  },
  {
    path:'/find',
    name:"Find",
    component:()=>import('../views/Find.vue'),
  },
  {
    path:'/message',
    name:"Message",
    component:()=>import('../views/Message.vue'),
  },
  {
    path:'/user',
    name:"User",
    component:()=>import('../views/User.vue'),
  },
  {
    path:'/landlord',
    name:"Landlord",
    component:()=>import('../views/Landlord.vue'),
  },

],
})

/* router.beforeEach((to,from,next)=>{
  if(to.meta.needLogin){
    if(isLogined()){
      next()
    }else{
      next({
        name:"Login",
      })
    }
  }else{
    next();
  }
}) */
 
//创建路由
/* export default createRouter({
  history:createWebHashHistory(),
  routes,
}) */

export default router;